package com.fluagen.example.vertx.asyn;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;

public class Server extends AbstractVerticle {

	public void start(Future<Void> startFuture) {

		HttpServer server = vertx.createHttpServer();

		Handler<HttpServerRequest> handler = e -> {
			HttpServerResponse response = e.response();
			response.putHeader("content-type", "application/json").end("hi asyn verticle");
		};
		
		server.requestHandler(handler).listen(8081, ah -> {
			if (ah.succeeded()) {
				System.out.println("Server is now listening!");
				startFuture.complete();
			} else {
				System.out.println("Failed to bind!");
				startFuture.failed();
			}
		});

	}
}
